import { defineStore } from "pinia";
import { login } from '@/api/user'
import { UserLogin } from "@/types/user";
import { constantRoute } from "@/router/routers"
let useUserStore = defineStore("User", {
    state: () => {
        return {
            token: localStorage.getItem("TOKEN"),
            routers: constantRoute
        }
    },
    actions: {
        async userLogin(data: UserLogin) {
            let result = await login(data)
            if (result.code === 10000) {
                this.token = result.data.token
                localStorage.setItem("TOKEN", result.data.token)
                return "ok"
            } else {
                return Promise.reject(new Error(result.msg))
            }
        }
    },
    getters: {

    }
})
export default useUserStore